dataconnect(chore): add logic to integrate network state changes with exponential backoff logic#8421
dataconnect(chore): add logic to integrate network state changes with exponential backoff logic#8421dconeybe wants to merge 7 commits into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a cold Flow to monitor network connectivity changes and signal when connection restoration is possible, accompanied by comprehensive unit tests. Additionally, it introduces mutable primitive wrappers and custom property-based test generators (like Arb.any) to the test utilities. The review feedback highlights a logic error in the Arb.any generator where extras are incorrectly duplicated within a loop, as well as a minor formatting typo in the changelog.
#8421 (comment) The `addAll(extras)` call is inside the `forEach` loop of `allScalarArbFactories`. This causes the `extras` list to be duplicated and added to `scalarArbs` multiple times (once for each scalar factory), which skews the random distribution of `Arb.any` heavily towards the extras. Moving it outside the loop resolves this issue. ```suggestion val scalarArbs = buildList { allScalarArbFactories.forEach { if (it.type !in excludes) { add(it.factory()) } } addAll(extras) } ```
#8421 (comment) There is a typo in the parentheses formatting. The second line has an extra opening parenthesis `(` before the pull request link.
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
This PR adds a mechanism to monitor network connectivity changes on Android (using
ConnectivityManager) and emit events when the network appears to be restored. This allows downstream connection retry backoff mechanisms to abort retry delays and attempt to reconnect immediately when network connectivity is restored.NOTE: This PR does NOT affect the exponential backoff mechanism. That will come in a subsequent PR. This PR ONLY adds the functionality that will be used by the exponential backoff logic.
Highlights
networkConnectivityRestoredFlowwhich creates a cold Flow ofNetworkConnectivityRestoredevents. It monitors Android network changes on API 23+, tracking available and validated networks, and only signaling on meaningful connectivity transitions.signalIfNotNullextension function toConflatedSignalto simplify signaling with nullable values.MutableBoolean,MutableInt, etc.) andArb.Companion.any()generators for Kotest to facilitate robust property-based testing of dynamic objects and collections.Changelog
networkConnectivityRestoredFlowusingConnectivityManager.NetworkCallbackwith support for different API levels (usingregisterDefaultNetworkCallbackon API 24+ and custom requests on API 23) to emitNetworkConnectivityRestoredsignals.ConflatedSignal.signalIfNotNullextension function.networkConnectivityRestoredFlowto verify callback scenarios under various network status, capability, and validation changes.signalIfNotNull.MutableBoolean,MutableByte,MutableShort,MutableInt,MutableLong,MutableChar,MutableFloat,MutableDouble,MutableReference).Arb.Companion.anygenerator for Kotest property-based tests.Arbgenerators for the new mutable primitives.